pcnn.tex (3765B)
1 \begin{tikzpicture}[ 2 word/.style={text depth=0,anchor=center,inner sep=0}, 3 flow/.style={thin,-latex,color=black!80}, 4 square/.style={regular polygon,regular polygon sides=4, inner sep=0}, 5 sidebrace/.style={decorate,decoration={brace,amplitude=0.3em,mirror}}, 6 sidenote/.style={left,midway,xshift=-0.4em,text depth=0}, 7 transform/.style={rotate=-90,draw,align=center,scale=0.7,rounded corners=0.1cm}] 8 9 \foreach \i/\da/\db/\name/\text in { 0/-2/-8/x00/Founded, 10 1/-1/-7/x01/in, 11 2/ / /e1/\strong{Rome}, 12 3/ 1/-5/x10/{(}, 13 4/ 2/-4/x11/then, 14 5/ 3/-3/x12/capital, 15 6/ 4/-2/x13/of, 16 7/ 5/-1/x14/the, 17 8/ / /e2/\strong{Papal States}, 18 9/ 7/ 1/x20/{)}, 19 10/ 8/ 2/x21/in, 20 11/ 9/ 3/x22/1575, 21 12/10/ 4/x23/by, 22 13/11/ 5/x24/St, 23 14/12/ 6/x25/Philip, 24 15/13/ 7/x26/\ldots}{ 25 \node[word] (t\name) at (-0.3, -0.3*\i+0.4*0.3) {\footnotesize \text}; 26 \node at (2.4, -0.3*\i+0.15) {\scriptsize \da}; 27 \node at (2.8, -0.3*\i+0.15) {\scriptsize \db}; 28 \node[draw,minimum width=20mm,minimum height=0.3cm,anchor=north west] (\name) at (1, -0.3*\i+0.3) {}; 29 } 30 31 \draw (2.6, 0.3) -- (2.6, -4.5); 32 \draw (2.2, 0.3) -- (2.2, -4.5); 33 34 \draw[flow] (x00.east) -- (4, -0.55); 35 \draw[flow] (x01.east) -- (4, -0.65); 36 \draw[flow] (x10.east) -- (4, -1.95); 37 \draw[flow] (x11.east) -- (4, -2.05); 38 \draw[flow] (x12.east) -- (4, -2.15); 39 \draw[flow] (x13.east) -- (4, -2.25); 40 \draw[flow] (x14.east) -- (4, -2.35); 41 \draw[flow] (x20.east) -- (4, -3.3); 42 \draw[flow] (x21.east) -- (4, -3.4); 43 \draw[flow] (x22.east) -- (4, -3.5); 44 \draw[flow] (x23.east) -- (4, -3.6); 45 \draw[flow] (x24.east) -- (4, -3.7); 46 \draw[flow] (x25.east) -- (4, -3.8); 47 \draw[flow] (x26.east) -- (4, -3.9); 48 49 \draw[pattern=north east lines,pattern color=Dark2-C,draw=none] (e1.north west) rectangle (e1.south east); 50 \draw[pattern=north east lines,pattern color=Dark2-C,draw=none] (e2.north west) rectangle (e2.south east); 51 52 \draw [sidebrace] (tx00.north -| -1.4,0) -- (tx01.south -| -1.4,0) node [sidenote] {prefix}; 53 \draw [sidebrace] (tx10.north -| -1.4,0) -- (tx14.south -| -1.4,0) node [sidenote] {infix}; 54 \draw [sidebrace] (tx20.north -| -1.4,0) -- (tx26.south -| -1.4,0) node [sidenote] {suffix}; 55 56 \node[draw,square,fill=black!20,rounded corners=0.1cm] (linear) at (8, -2) {Linear}; 57 \node[transform,minimum width=1.4cm/0.7,anchor=north] (softmax) at (9.3, -2) {softmax}; 58 59 \node[right=2mm of softmax.north] {\(P(\rndm{r}\mid s)\)}; 60 61 \draw [sidebrace] (2.25, -4.6) -- (3, -4.6) node [below,midway,yshift=-1mm,xshift=-3mm,align=left,text width=4cm,anchor=north west] {positional\\embeddings}; 62 \draw [sidebrace] (1, -4.6) -- (2.15, -4.6) node [below,midway,yshift=-1mm,xshift=3mm,align=right,text width=4cm,anchor=north east] {\hfill word\\\hfill embeddings}; 63 64 \foreach \i/\n in {-1/p,-2.5/i,-4/s}{ 65 \foreach \j/\c in {0.3/20,0.2/40,0.1/20,0/40}{ 66 \filldraw[fill=black!\c,fill opacity=0.7,rounded corners=0.05cm] (4+\j, \i+\j) rectangle +(0.8, 0.8); 67 } 68 \node at (4+0.4, \i+0.4) {\footnotesize Conv}; 69 70 \node[transform,minimum width=1.1cm/0.7,anchor=north east] at (6, \i) {max\\pooling}; 71 \node[transform,minimum width=1.1cm/0.7,anchor=north east] (relu\n) at (6.5, \i) {tanh}; 72 73 \draw[flow] (relu\n) -- (linear); 74 } 75 \end{tikzpicture}